package cn.dengta.webapp.trade.vo;

import java.io.Serializable;
import java.util.*;

import cn.dengta.common.context.I18N;
import cn.dengta.context.model.TradeI18nKey;
import cn.dengta.webapp.user.model.UserVipRule;
import lombok.*;
import me.codeplayer.util.*;

import static cn.dengta.webapp.trade.entity.UserVipEquity.ExtendUserVipVO;

@Setter
@Getter
public class UserVipProductVO implements Serializable {

	/** 等級 */
	private Integer level;
	/** VIP图片 */
	private String icon;
	/** VIP 名称 */
	private String name;
	/** 是否可选 */
	private Boolean optional;
	/** 标题 */
	private String title;
	/** VIP 配置 */
	private List<UserVipInfoVO> infos;

	public void ofInfoVO(UserVipRule rule, List<ExtendUserVipVO> list, boolean check, Locale locale) {
		List<UserVipInfoVO> vos = new ArrayList<>();
		if (X.isValid(list)) {
			Map<String, String> map = CollectionUtil.toHashMap(list, ExtendUserVipVO::getName, ExtendUserVipVO::getIcon);
			if (Cmp.eq(rule.getVipGift(), 1)) {
				vos.add(new UserVipInfoVO(map.get(UserVipRule.VIP_GIFT), I18N.msg(TradeI18nKey.USER_VIP_GIFT, locale)));
			}
			if (Cmp.gt(rule.getCoinDay(), 0)) {
				vos.add(new UserVipInfoVO(map.get(UserVipRule.COIN_DAY), I18N.msg(TradeI18nKey.USER_VIP_COIN_DAY, locale, rule.getCoinDay())));
			}
			if (Cmp.eq(rule.getVipTag(), 1)) {
				vos.add(new UserVipInfoVO(map.get(UserVipRule.VIP_TAG), I18N.msg(TradeI18nKey.USER_VIP_TAG, locale)));
			}
			if (Cmp.eq(rule.getVipRecommend(), 1)) {
				vos.add(new UserVipInfoVO(map.get(UserVipRule.VIP_RECOMMEND), I18N.msg(TradeI18nKey.USER_VIP_RECOMMEND, locale)));
			}
			if (!check && Cmp.gt(rule.getAudioMinute(), 0)) {
				vos.add(new UserVipInfoVO(map.get(UserVipRule.AUDIO_MINUTE), I18N.msg(TradeI18nKey.USER_VIP_AUDIO_MINUTE, locale, rule.getAudioMinute())));
			}
			if (Cmp.gt(rule.getCoinNum(), 0)) {
				vos.add(new UserVipInfoVO(map.get(UserVipRule.COIN_NUM), I18N.msg(TradeI18nKey.USER_VIP_COIN_NUM, locale, rule.getCoinNum())));
			}
			if (!check && Cmp.gt(rule.getVideoMinute(), 0)) {
				vos.add(new UserVipInfoVO(map.get(UserVipRule.VIDEO_MINUTE), I18N.msg(TradeI18nKey.USER_VIP_VIDEO_MINUTE, locale, rule.getVideoMinute())));
			}
			if (Cmp.eq(rule.getExposure(), 1)) {
				vos.add(new UserVipInfoVO(map.get(UserVipRule.EXPOSURE), I18N.msg(TradeI18nKey.USER_VIP_EXPOSURE, locale)));
			}
		}
		this.infos = vos;
	}

	@Setter
	@Getter
	@AllArgsConstructor
	@NoArgsConstructor
	public static class UserVipInfoVO {

		/** 权益图片 */
		private String icon;
		/** 权益信息 */
		private String info;
		/** 二级标题 */
		private String title;

		public UserVipInfoVO(String icon, String info) {
			this.icon = icon;
			this.info = info;
		}

	}

}
